﻿using System.Diagnostics;
using System.Text;
using XA_DATASETLib;

namespace IRUM.TR
{
    public abstract class CBaseReal
    {
        protected const string InBlockName = "InBlock";
        protected const string OutBlockName = "OutBlock";

        protected TR_Type type;
        protected string classname = string.Empty;

        protected XAReal m_Real = new XAReal();


        protected void SetClassData(TR_Type tr_type)
        {
            type = tr_type;
            classname = type.ToString();

            m_Real.ResFileName = @"C:\ETRADE\xingAPI\Res" + type.ToString() + ".res";
            m_Real.ReceiveRealData += m_Real_ReceiveRealData;
            m_Real.RecieveLinkData += m_Real_RecieveLinkData;
        }

        void m_Real_RecieveLinkData(string szLinkName, string szData, string szFiller)
        {
            throw new System.NotImplementedException();
        }

        void m_Real_ReceiveRealData(string szTrCode)
        {
            HandleQuery();
        }

        protected void AddLog(string log)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            sb.Append(classname);
            sb.Append("]\t");
            sb.Append(log);

            Debug.Print(sb.ToString());
        }

        public abstract void HandleQuery();

        protected abstract void SetRequestData();

        public void Request()
        {
            SetRequestData();
            m_Real.AdviseRealData();
        }

        public void Dispose()
        {
            m_Real.UnadviseRealData();
        }
    }
}
